<template>
  <app-layout viewName="res_partnertreeview" viewTitle="客户树视图" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'detreeview': true, 'res-partner-tree-view': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
        
<div class="tree-contant">
    <view_tree 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context" 
    :showBusyIndicator="true"
    updateAction='Update' 
    removeAction='Remove' 
    loadAction='Get' 
    createAction='Create' 
    name="tree"  
    ref='tree' 
    @selectionchange="tree_selectionchange($event)"  
    @load="tree_load($event)"  
    @closeview="closeView($event)">
</view_tree>
</div>


      </div>
    </template>
  </app-layout>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, TreeViewBase } from '@/crm-core';
import Res_partnerService from '@/service/res-partner/res-partner-service';

import TreeViewEngine from '@engine/view/tree-view-engine';


/**
 * 客户树视图基类
 *
 * @export
 * @class Res_partnerTreeViewBase
 * @extends {TreeViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class Res_partnerTreeViewBase extends TreeViewBase {

    /**
     * 实体服务对象
     *
     * @type {Res_partnerService}
     * @memberof Res_partnerTreeViewBase
     */
    public appEntityService: Res_partnerService = new Res_partnerService;

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof Res_partnerTreeViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof Res_partnerTreeViewBase
	 */
	public viewtag: string = '1c3d20171aabff4b3173cfce4b3e0dd1';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof Res_partnerTreeViewBase
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof Res_partnerTreeViewBase
	 */
    protected customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof Res_partnerTreeViewBase
	 */
    protected customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof Res_partnerTreeViewBase
     */
    public model: any = {
        srfCaption: 'entities.res_partner.views.treeview.caption',
        srfTitle: 'entities.res_partner.views.treeview.title',
        srfSubTitle: 'entities.res_partner.views.treeview.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof Res_partnerTreeViewBase
     */
    public containerModel: any = {
        view_tree: { name: 'tree', type: 'TREEVIEW' },
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof Res_partnerTreeViewBase
     */
    public viewState: Subject<ViewState> = new Subject();


    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof Res_partnerTreeViewBase
     */
    public engine: TreeViewEngine = new TreeViewEngine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof Res_partnerTreeViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            tree: this.$refs.tree,
            keyPSDEField: 'res_partner',
            majorPSDEField: 'name',
            isLoadDefault: true,
        });
    }


    /**
     * tree 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Res_partnerTreeViewBase
     */
    public tree_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('tree', 'selectionchange', $event);
    }


    /**
     * tree 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Res_partnerTreeViewBase
     */
    public tree_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('tree', 'load', $event);
    }





    /**
     * 销毁视图回调
     *
     * @memberof Res_partnerTreeViewBase
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }


    /**
     * 节点过滤值
     *
     * @type {string}
     * @memberof Res_partnerTreeView
     */
    public srfnodefilter: string = '';

    /**
     * 快速搜索
     *
     * @returns {void}
     * @memberof Res_partnerTreeView
     */
    public onSearch(): void {
        if (!this.viewState) {
            return;
        }
        this.viewState.next({ tag: 'tree', action: 'filter', data: { srfnodefilter: this.srfnodefilter } });
    }
    
}
</script>

<style lang='less'>
@import './res-partner-tree-view.less';
</style>